package com.example.rocket.controller;

import com.alibaba.fastjson.JSON;
import com.example.rocket.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 引入的是spring封装后的rocketMQ坐标
 * 所以配置文件中配置之后，无需在这里配置name-server
 *
 * @Author ifredomvip@gmail.com
 * @Date 2022/8/16 16:12
 * @Version 1.0.0
 * @Description
 **/
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "user-consumer", topic = "topic-user")
public class ConsumerUserMessage implements RocketMQListener<UserEntity> {

    @Override
    public void onMessage(UserEntity user) {
        // 重写消息处理方法
        String msg = JSON.toJSONString(user);
        log.info("------- userConsumer received:{} \n", msg);

        // TODO 对消息进行处理，比如写入数据
    }
}
